package com.lineage.server.datatables.lock;

import com.lineage.server.datatables.sql.CharMapTimeTable;
import com.lineage.server.datatables.storage.CharMapTimeStorage;
import com.lineage.server.model.Instance.L1PcInstance;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class CharMapTimeReading {
  private final Lock _lock = new ReentrantLock(true);
  
  private final CharMapTimeStorage _storage = (CharMapTimeStorage)new CharMapTimeTable();
  
  private static CharMapTimeReading _instance;
  
  public static CharMapTimeReading get() {
    if (_instance == null)
      _instance = new CharMapTimeReading(); 
    return _instance;
  }
  
  public void load() {
    this._lock.lock();
    try {
      this._storage.load();
    } finally {
      this._lock.unlock();
    } 
  }
  
  public Map<Integer, Integer> addTime(int objId, int order_id, int used_time) {
    Map<Integer, Integer> tmp;
    this._lock.lock();
    try {
      tmp = this._storage.addTime(objId, order_id, used_time);
    } finally {
      this._lock.unlock();
    } 
    return tmp;
  }
  
  public void getTime(L1PcInstance pc) {
    this._lock.lock();
    try {
      this._storage.getTime(pc);
    } finally {
      this._lock.unlock();
    } 
  }
  
  public void deleteTime(int objid) {
    this._lock.lock();
    try {
      this._storage.deleteTime(objid);
    } finally {
      this._lock.unlock();
    } 
  }
  
  public void saveAllTime() {
    this._lock.lock();
    try {
      this._storage.saveAllTime();
    } finally {
      this._lock.unlock();
    } 
  }
  
  public void clearAllTime() {
    this._lock.lock();
    try {
      this._storage.clearAllTime();
    } finally {
      this._lock.unlock();
    } 
  }
  
  public void update(int objid, int mapid, int time) {
    this._lock.lock();
    try {
      this._storage.update(objid, mapid, time);
    } finally {
      this._lock.unlock();
    } 
  }
}
